package com.ssm.basis.service.exception;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * 自定义异常、业务异常
 * BusinessException
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class CustomException extends RuntimeException {
    private static final long serialVersionUID = 3169641586916324994L;
    String code;

    public CustomException(String message) {
        super(message);
    }

    public CustomException(Throwable cause) {
        super(cause);
    }

    public CustomException(ExceptionEnum exceptionEnum) {
        this(exceptionEnum.getCode(), exceptionEnum.getMessage());
    }

    public CustomException(String code, String message) {
        this(message);
        this.code = code;
    }

    public CustomException(ExceptionEnum exceptionEnum, Object... args) {
        this(exceptionEnum.getCode(), exceptionEnum.getMessage(), args);
    }

    public CustomException(String code, String messageFormat, Object... args) {
        this(String.format(messageFormat, args));
        this.code = code;
    }
}
